package cn.bearspark.api.controller.main;

import cn.bearspark.api.vo.main.user.*;
import cn.bearspark.api.service.main.UserService;
import cn.bearspark.framework.web.starter.vo.ResponseVO;
import jakarta.validation.Valid;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

/**
 * 用户模块
 *
 * @author f
 */
@Validated
@CrossOrigin
@RestController
@RequestMapping("/user")
public class UserController {

    private final UserService userService;

    public UserController(UserService userService) {
        this.userService = userService;
    }

    /**
     * 发送验证码
     *
     * @param sendReqVO 指定的手机号
     * @return 发送验证码的响应对象
     */
    @PostMapping("/send")
    public ResponseVO<Object> send(@Valid @RequestBody SendReqVO sendReqVO) {
        return userService.send(sendReqVO);
    }

    /**
     * 验证验证码
     *
     * @param verifyReqVO 验证的请求对象
     * @return 验证的响应对象
     */
    @PostMapping("/verify")
    public ResponseVO<Object> verify(@Valid @RequestBody VerifyReqVO verifyReqVO) {
        return userService.verify(verifyReqVO);
    }

    /**
     * 初始化密码
     *
     * @param passwordReqVO 初始化密码的请求对象
     * @return 初始化密码的响应对象
     */
    @PostMapping("/password")
    public ResponseVO<Object> initPassword(@Valid @RequestBody PasswordReqVO passwordReqVO) {
        return userService.initPassword(passwordReqVO);
    }

    /**
     * 修改密码
     *
     * @param passwordReqVO 修改密码的请求对象
     * @return 修改密码的响应对象
     */
    @PutMapping("/password")
    public ResponseVO<Object> modifyPassword(@Valid @RequestBody PasswordReqVO passwordReqVO) {
        return userService.modifyPassword(passwordReqVO);
    }

    /**
     * 用户登录
     *
     * @param loginReqVO 登录请求的对象
     * @return 登录请求的响应
     */
    @PostMapping("/login")
    public ResponseVO<LoginRespVO> login(@Valid @RequestBody LoginReqVO loginReqVO) {
        return userService.login(loginReqVO);
    }

}
